package com.code.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

/**
 * 切面类
 */
@Aspect
public class LogAspect {

    //抽取公共的切入点表达式
    //1、本类引用
    @Pointcut("execution(public int com.code.aop.MathCalculator.*(..))")
    public void pointCut(){}

    //在目标方法之前切入：切入点表达式（指定在哪个方法切入）
    @Before("com.code.aop.LogAspect.pointCut()")
    public void logStart(JoinPoint joinPoint){
        System.out.println("Before "+joinPoint.getSignature().getName()+"除法运行。。。参数列表是：{"+ Arrays.asList(joinPoint.getArgs())+"}");
    }

    @After("pointCut()")
    public void logEnd(JoinPoint joinPoint){

        System.out.println("After "+joinPoint.getSignature().getName()+"除法运行结束。。。@After(\"pointCut()\")");
    }

    @AfterReturning(value = "pointCut()",returning ="result" )
    public void logReturn(JoinPoint joinPoint,Object result){
        System.out.println("AfterReturning "+joinPoint.getSignature().getName()+"除法正常返回。。运行结果：{"+result+"}");
    }

    @AfterThrowing(value = "pointCut()",throwing = "exception")
    public void LogException(JoinPoint joinPoint,Exception exception){
        System.out.println("AfterThrowing "+joinPoint.getSignature().getName()+"除法异常。。异常信息：{}"+exception);
    }

}
